/*
	MIDAS Context Based Routing
	cbr_timers.cc
	Copyright (c) 2007 Radoslaw Olgierd Schoeneich
	MEAG IT PW
 */

#include <stdlib.h>

#include "scheduler.h"

#include "cbr.h"
#include "cbr_address.h"
#include "cbr_debug.h"

/**
 * Handles purging of CBR message cache.
 *
 * Called by events scheduler.  Tries to purge stale CBR messages
 * from the message cache and then queues itself again into events
 * list of the scheduler.
 *
 * CACHE_PURGE_FREQ define controls how often CBR message cache
 * is purged.
 */

void cbr_MsgCacheTimer::handle(Event*)
{
	if (cbr_log_functions())
		cbr_log("in %s()\n", __func__);
	agent->purgeMsgCache();
	Scheduler::instance().schedule(this, &intr, CACHE_PURGE_FREQ);
}

/**
 * Handles purging of CBR routes table.
 *
 * Called by events scheduler.  Tries to purge CBR routes from
 * the CBR routes cache and then queues itself again into events
 * list of the scheduler.
 *
 * CACHE_PURGE_FREQ define controls how often CBR routes cache
 * is purged.
 */

void cbr_CRTableTimer::handle(Event*)
{
	if (cbr_log_functions())
		cbr_log("in %s()\n", __func__);
	agent->purgeCRTable();
	Scheduler::instance().schedule(this, &intr, CACHE_PURGE_FREQ);
}
